﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace KHOALUAN
{
    public partial class frmCaiDatCTHoc : Form
    {
        private bool CaiDatTheoKhoa = true;
        public frmCaiDatCTHoc()
        {
            InitializeComponent();
        }

        private void frmCaiDatCTHoc_Load(object sender, EventArgs e)
        {
            try
            {
                LoadDataToComboBox();
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmCaiDatCTHoc_Load... \n\nChi tiết:\n" + ex, "Thông báo lỗi");
            }
        }
        private void LoadDataToComboBox()
        {
            try
            {
                cmb.Items.Clear();
                if (CaiDatTheoKhoa == true)
                {
                    XElement xGV = XElement.Load(clsMain.DATA_PATH + "KHOA" + ".xml");
                    IEnumerable<XElement> Columns = xGV.Elements();
                    foreach (var col in Columns)
                    {
                        if (col.Name != "ColumnNames")
                        {
                            cmb.Text = col.Element("TENKH").Value.ToString();
                            cmb.Items.Add(col.Element("TENKH").Value.ToString());
                        }
                    }
                    
                }
                else
                {
                    XElement xGV = XElement.Load(clsMain.DATA_PATH + "LOPHOC" + ".xml");
                    IEnumerable<XElement> Columns = xGV.Elements();
                    int i = 0;
                    foreach (var col in Columns)
                    {
                        if (col.Name != "ColumnNames")
                        {
                            cmb.Text = col.Element("TENLH").Value.ToString();
                            cmb.Items.Add(col.Element("TENLH").Value.ToString());
                            cmb.Items.Add(new ComboItem("some value 1", 1234));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("LoadDataToComboBox... \n\nChi tiết:\n" + ex, "Thông báo lỗi");
            }
        }

        private void rdbKhoa_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                if (rdbKhoa.Checked == true)
                {
                    CaiDatTheoKhoa = true;
                }
                else
                {
                    CaiDatTheoKhoa = false;
                }
                LoadDataToComboBox();
            }
            catch (Exception ex)
            {
                MessageBox.Show("rdbKhoa_CheckedChanged... \n\nChi tiết:\n" + ex, "Thông báo lỗi");
            }
        }
    }
}
